from datetime import datetime
from django.db import models
from django.forms import ModelForm


class Wheel(models.Model):
    WHEEL_SIZE = (
        (16, '16"'),
        (17, '17"'),
        (18, '18"'),
        (19, '19"'),
    )
    CUSTOMER = (
        ('美', '美国'),
        ('韩', '韩国'),
        ('印', '印度'),
        ('巴', '巴西'),
    )
    COLOR = (
        ('银', '银色'),
        ('灰', '灰色'),
        ('黒', '黒色'),
    )
    HOLE = (
        ('一般', '一般'),
        ('特殊', '特殊'),
    )

    marker = models.CharField(max_length=50)  # 1-型号
    size = models.IntegerField(choices=WHEEL_SIZE)  # 2-尺寸: 16 17 18 19
    valve_hole = models.CharField(max_length=20, choices=HOLE)  # 3-气门嘴
    technique = models.CharField(max_length=20)  # 4-工艺
    color = models.CharField(max_length=20, choices=COLOR)  # 5-颜色
    customer = models.CharField(max_length=20, choices=CUSTOMER)  # 6-客户
    image_top = models.CharField(max_length=100)
    image_code = models.CharField(max_length=100)
    print_counter = models.IntegerField(default=0)
    created = models.DateTimeField(default=datetime.now)  # 7-创建时间


class WheelForm2(ModelForm):
    class Meta:
        model = Wheel
        fields = ['marker', 'size', 'valve_hole', 'technique', 'color', 'customer', 'image_top', 'image_code']
        exclude = ['created']


class History(models.Model):
    wheel_id = models.IntegerField()
    index = models.CharField(max_length=6)
    image_top = models.CharField(max_length=100)
    wheel_size = models.CharField(max_length=20, default='16')
    created = models.DateTimeField(default=datetime.now)


class HistoryForm(ModelForm):
    class Meta:
        model = History
        fields = ['index', 'image_top', 'wheel_id', 'wheel_size']
        # exclude = ['wheel_id']
